<?php 
require_once 'header.inc.php';

if(isset($_SESSION['user'])){
	header("Location:index.php");
	exit;
}

if(isset($_POST['username'])){
	$user = $_POST['username'];
	$pwd  = $_POST['password'];
	
	$user = mysql_real_escape_string($user);
	$pwd = mysql_real_escape_string($pwd);
	
	$loginSql = "SELECT * FROM `user` WHERE `name` = '$user' AND `pwd`='$pwd'";
	
	$result = mysql_query($loginSql);
	
	if($result!=false && mysql_num_rows($result)==1){
		$_SESSION['user'] = $user;
		header("Location:index.php");
		exit();
	}
	else{
		echo <<<ERROR
		<script type="text/javascript">
				alert("用户名或密码错误");
				window.location.history.go(-1);
		</script>
ERROR;
	}
}
?>
	<!-- 处理用户提交表单 -->
		
		<!-- 面包屑（即“留言板->登录”之类的内容）-->
		<div class="navbar clearfix"> 
			<div class="breadcrumb"> 
				<ul> 
					<li class="first"><a href="index.php">简单留言板</a></li>
					<li> <span class="arrow sep">&#x25BA;</span> 登录 </li>
				</ul>
			</div> 			
		</div> 

<div id="content"> 
<div class="loginbox clearfix twocolumns"> 
  <div class="loginpanel"> 
    <h2>欢迎访问本站</h2> 
      <div class="subcontent loginsub"> 
        <div class="desc"> 
          请使用用户名和密码登录<br/>(您的浏览器的Cookies设置必须打开)</div> 
                <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="login"> 
          <div class="loginform"> 
            <div class="form-label">
				<label for="username">用户名</label>
			</div> 
            <div class="form-input"> 
              <input type="text" name="username" id="username" size="15" value="" /> 
            </div> 

            <div class="clearer"></div> 

            <div class="form-label">
				<label for="password">密码</label>
			</div> 
            <div class="form-input"> 
              <input type="password" name="password" id="password" size="15" value="" /> 
            </div> 

			<div class="clearer"></div> 

			<div class="form-label">
				<label for="password">保持登录</label>
			</div> 
           
              <input type="radio" name="day" value="1" />1天       
			  <input type="radio" name="day" value="7" />1周
			 <input type="radio" name="day" value="31" />1月
			  <input type="radio" name="day" value="365" />1年
          
			
			<div class="clearer"></div> 

            <div class="form-input"> 
              <input type="submit" name="login" id="submit" value="登录" /> 
			  <input type="button" name="visit" id="submit" value="游客浏览" onclick="javascript: window.location.href = 'index.php';" />
            </div> 

            <div class="clearer"></div> 
          </div> 
        </form> 
      </div> 
      
     </div> 
    <div class="signuppanel"> 
      <h2>常见问题</h2> 
      <div class="subcontent"> 
		<p><b>还没有用户名？</b> <br /> 
			本留言板必须用户登录后，才可以发表留言，游客只能查看留言，还等什么，快来<a href="register.php">注册</a>吧！<br />
			<br />
			<b>忘记密码了？</b> <br /> 
			密码忘记了，怎么办呢？还记得注册时填写的密码保护问题吗？快去<a href="fetchPswd.php">重设密码</a>吧！<br /></p>      </div> 
	  </div> 
</div> 
 
</div> <!-- end div containerContent --> 
	
<!-- 引入页脚文件 -->
<?php 
require_once 'footer.inc.php';
?>





